<include file="Common:minheader" />
<!-- /. NAV SIDE  -->
<form class="layui-form" action="">
	<div class="layui-form-item">
		<label class="layui-form-label">名称</label>
		<div class="layui-input-block">
		  <input type="text" name="title" required  lay-verify="required" placeholder="请输入优惠券名称" autocomplete="off" class="layui-input">
		</div>
	</div>
   <div class="layui-form-item">
		<label class="layui-form-label">是否全场</label>
		<div class="layui-input-block">
		  <input type="radio" name="cate" value="1" title="积分兑换" checked>
		  <input type="radio" name="cate" value="2" title="全场">
		</div>
	</div>
	<!--<div class="layui-form-item">-->
	<!--	<label class="layui-form-label">图片</label>-->
	<!--	<div class="layui-input-block">-->
	<!--		<div class="layui-upload">-->
	<!--		  <button type="button" class="layui-btn" id="test2">上传图片</button>-->
	<!--		  <div class="layui-upload-list" id="demo2" data-id="">-->
	<!--			<if condition="!empty($info['image_url'])">-->
	<!--				<div class="imgcss"><input type="hidden" name="image_url" id="smallimage1" value="{$info.image_url}"><a href="{$info.image_url}" target="_blank"><img src="{$info.image_url}" width="150"></a></div>-->
	<!--			</if>-->
	<!--		  </div>-->
	<!--		  <div id="demoText1"></div>-->
	<!--		</div> -->
	<!--	</div>-->
	<!--</div>-->
	<div class="layui-form-item">
		<label class="layui-form-label">满足金额</label>
		<div class="layui-input-block">
		  <input type="text" name="condition_amount" required  lay-verify="required" placeholder="请输入满足条件金额" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">优惠金额</label>
		<div class="layui-input-block">
		  <input type="text" name="coupon" required  lay-verify="required" placeholder="请输入优惠金额" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">兑换积分</label>
		<div class="layui-input-block">
		  <input type="text" name="integral" required  lay-verify="required" placeholder="请输入兑换积分，如果是全场输入0" autocomplete="off" class="layui-input">
		</div>
	</div>
   <div class="layui-form-item">
		<label class="layui-form-label">开始时间</label>
		<div class="layui-input-block">
		  <input type="text" name="validity_begin_time" required  lay-verify="required" placeholder="请输入开始时间" autocomplete="off" class="layui-input" id="addtime_fromdate">
		</div>
	</div>
   <div class="layui-form-item">
		<label class="layui-form-label">结束时间</label>
		<div class="layui-input-block">
		  <input type="text" name="validity_end_time" required  lay-verify="required" placeholder="请输入结束时间" autocomplete="off" class="layui-input" id="addtime_todate">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">序号</label>
		<div class="layui-input-inline">
		  <input value="0" type="text" name="sort" placeholder="请输入序号" autocomplete="off" class="layui-input">
		</div>
		<div class="layui-form-mid layui-word-aux">数字越大排序越靠前</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否启用</label>
		<div class="layui-input-block">
		  <input type="radio" name="status" value="1" title="是" checked>
		  <input type="radio" name="status" value="0" title="否">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
		  <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
  </div>
</form>
<script>
	//Demo
	layui.use('form', function(){
	  var form = layui.form;
	  layui.use('upload', function(){
    		var $ = layui.jquery
    		,upload = layui.upload;
    		var uploadInst = upload.render({
    			elem: '#test2'
    			,url: "{:U('Common/uploadImage')}"
    			,size:'0'
    			,exts:'jpeg|gif|png|jpg'
    			,multiple: false
    			,method: 'POST'
    			,before: function(obj){
    				//预读本地文件示例，不支持ie8
    				obj.preview(function(index, file, result){
    					$('#demo2').html('<div class="imgcss"><input type="hidden" name="image_url" id="smallimage1"><img src="'+result+'" width="150"></div>'); //文件名
    				});
    			}
    			,done: function(res){
    				//如果上传失败
    				if(res.code==0){
    					return layer.msg(res.value);
    				}else{
    					$('#smallimage1').val(res.value);
    				}
    			}
    			,error: function(){
    				//演示失败状态，并实现重传
    				var demoText = $('#demoText1');
    				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
    				demoText.find('.demo-reload').on('click', function(){
    					uploadInst.upload();
    				});
    			}
    		});
    	});
	  //监听提交
	  form.on('submit(formDemo)', function(data){
			var cont = data.field;
			$.ajax({
				url:"{:U('Coupons/addCoupons')}",
				type:'post',
				dataType:'json',
				data:cont,
				success:function(data){
					if(data.code==0){
						layer.alert(data.message);
					}else{
						layer.alert(data.message, function(index){
							//do something
							window.parent.location.reload();
							var index = parent.layer.getFrameIndex(window.name); 
							parent.layer.close(index);
						});
					}
				}
			});
			//layer.msg(JSON.stringify(data.field));
			return false;
	  });
	});
</script>
<!-- /. PAGE INNER  -->
<include file="Common:footer" />